/*
 * PaymentGUI.java
 *
 * Created on March 27, 2007, 12:03 PM
 */

package edu.byu.isys413.jjenkins.view;
import edu.byu.isys413.jjenkins.data.*;

/**
 * This form is created inorder to initiate the payment process
 * @author byu
 */
public class PaymentGUI extends javax.swing.JFrame {
    
    //Singleton variable
    private static PaymentGUI instance = null;
    
    PaymentBO payment;
    
    /** Creates new form PaymentGUI */
    private PaymentGUI() {
        initComponents();
        pack();
                this.setLocationRelativeTo(null);
    }
    
    
        /* implements singleton pattern to insure that only one instance of this
         * gui is created*/
    
    /**
     * gets the single instance
     */
    public static synchronized PaymentGUI getInstance() {
        
        if (instance == null) {
            instance = new PaymentGUI();
        }
        
        return instance;
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jPanel5 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        cmbType = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        txtAmount = new javax.swing.JTextField();
        btnSave = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();

        getContentPane().setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Payment");
        jPanel5.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jPanel5.setPreferredSize(new java.awt.Dimension(450, 100));
        jPanel4.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jPanel4.setPreferredSize(new java.awt.Dimension(400, 20));
        jLabel3.setText("Enter Payment Information:");
        jLabel3.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(0, 0, 0)));
        jLabel3.setPreferredSize(new java.awt.Dimension(400, 15));
        jPanel4.add(jLabel3);

        jPanel5.add(jPanel4);

        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jPanel2.setPreferredSize(new java.awt.Dimension(400, 40));
        jLabel2.setText(" Type:    ");
        jPanel2.add(jLabel2);

        cmbType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Credit", "Cash", "Debit", "Check" }));
        cmbType.setPreferredSize(new java.awt.Dimension(100, 20));
        jPanel2.add(cmbType);

        jLabel1.setText("Amount: ");
        jPanel2.add(jLabel1);

        txtAmount.setPreferredSize(new java.awt.Dimension(100, 20));
        jPanel2.add(txtAmount);

        btnSave.setText("Post");
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        jPanel2.add(btnSave);

        jPanel5.add(jPanel2);

        jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jPanel3.setPreferredSize(new java.awt.Dimension(300, 40));
        jPanel5.add(jPanel3);

        getContentPane().add(jPanel5);

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        
        payment.setAmount(Double.parseDouble(txtAmount.getText()));
        payment.setType(cmbType.getSelectedItem().toString());//type is cash, credit, etc.
        NewOrder.getInstance().postTransaction(payment);
        //Hide Screen <this should lead to a reciept instead
        this.dispose();
        

    }//GEN-LAST:event_btnSaveActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new PaymentGUI().setVisible(true);
            }
        });
    }
    
    /**Populates the view
     *@param payment PaymentBO
     */
    public void populate(PaymentBO payment){
        this.payment = payment;
        this.setVisible(true);
     
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSave;
    private javax.swing.JComboBox cmbType;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JTextField txtAmount;
    // End of variables declaration//GEN-END:variables
    
}
